<template>
	<view class="pages">
		<view class="pages-map">
			<map 
				class="pages-map-content" 
				name="" 
				longitude="114.058032" 
				latitude="22.543610"
				:scale="16"
				:markers="[114.058032,22.543610]"
				enable-3D
				enable-zoom
				enable-overlooking
			></map>
		</view>
		<up-tabs
			activeStyle="#2E90EC"
			:scrollable="false"
			lineWidth="40rpx"
			:list="tabs"
			@click="onSkipTabs"
		></up-tabs>
		
		<scroll-view class="pages-content" scroll-y>
			<!-- 基本信息 -->
			<view class="pages-list-item" v-if="active === 'base'">
				<view class="pages-item-title">
					<text>{{ details.taskName || '--' }}</text>
					<!-- <text class="pages-item-title--tag" v-show="details.overdue == 1">逾期</text> -->
				</view>
				
				
				<view class="pages-item-row">
					<text class="pages-hint-title">所属社区</text>
					<text class="pages-hint-content">福保社区</text>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">所属网格</text>
					<text class="pages-hint-content">福保03</text>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">详细地址</text>
					<view class="pages-hint-content pages-hint-content--active" @click="onOpenMap">
						<up-icon 
							name="map" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="深圳市福田区新桂花村6号楼"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">核查人员</text>
					<view class="pages-hint-content pages-hint-content--active" @click="onCallPerson">
						<up-icon 
							name="phone" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="曾文勇/福田街道办"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
				<view class="pages-item-row">
					<text class="pages-hint-title">整改人员</text>
					<view class="pages-hint-content pages-hint-content--active" @click.stop="onOpenCall">
						<up-icon
							name="phone" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="应急办"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
				
				<view class="pages-item-bolck">
					<view class="pages-bolck-title">
						<text class="pages-bolck-title-ad"></text>
						自定义信息
					</view>
				</view>
				
				
				<view class="pages-item-row">
					<text class="pages-hint-title">任务板块</text>
					<text class="pages-hint-content">场所巡查</text>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">自定义文件</text>
					<view class="pages-hint-content pages-hint-content--active">
						<up-image
							:src="'http://101.33.235.253:9300/statics/2024/09/07/00034-1429399740_20240907195146A003.png'" 
							mode="aspectFit"
							width="100rpx"
							height="100rpx"
							radius="10rpx"
							:fade="true" 
							duration="450"
						></up-image>
					</view>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">场所类型</text>
					<text class="pages-hint-content">公益广告宣传（一周一次）</text>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">发布时间</text>
					<text class="pages-hint-content">{{ details.createTime || details.startDate || '--' }}</text>
				</view>
				
				<view class="pages-item-row">
					<text class="pages-hint-title">任务时间</text>
					<text class="pages-hint-content">{{ details.startDate || '--' }} 至 {{ details.endDate || '--' }}</text>
				</view>
			</view>
			
			<!-- 巡查记录 -->
			<view class="pages-list-item" v-if="active === 'log-1' || active === 'log-2'">
				<view 
					class="pages-list-items" 
					@click="onSkipRouterToDetail"
					v-for="item of 10"
					:key="item"
				>
					<view
						class="pages-item-status"
						:class="{
							'pages-item-status--warning' : item == 1,
							'pages-item-status--success':  item === 3
						}"
					> 
						{{  item === 1 ? '整改中' :  item === 3 ? '已整改' : '未发现' }}
						<!-- {{ item.taskStatus == 0 ? '待分拨' : item.taskStatus == 1 ? '已分拨' : item.taskStatus == 2 ? '已完成' : '待分拨' }} -->
					</view>
					
					<view class="pages-item-title">
						<text>
							李晓明{{ item }}<text style="font-size: 28rpx;margin-left: 10rpx;">福保01</text>
						</text>
						
						<text class="pages-item-title--tag" v-show="item == 4">逾期</text>
					</view>
					<view class="pages-item-row">
						<text class="pages-hint-title">处理时间</text>
						<text class="pages-hint-content">2024-09-24</text>
					</view>
				</view>
				
				<template v-if="false">
					<up-empty icon="list" marginTop="300rpx"></up-empty>
				</template>
				
				<up-loadmore line loadingIcon="circle" v-show="true" status="nomore" />
			</view>
			
			
			<view class="pages-buttons--fill" v-if="active === 'base'"></view>
		</scroll-view>
		
		<view class="pages-button" v-if="active === 'base'">
			<view style="width:48%;">
				<up-button
					color="#2E90EC" 
					text="编辑"
				></up-button>
			</view>
			<view style="width:48%;">
				<up-button
					type="error" 
					:plain="true" 
					text="删除"
				></up-button>
			</view>
		</view>
		<view class="pages-button" v-if="active === 'log-1'">
			<view style="width:100%;">
				<up-button
					color="#2E90EC" 
					text="新增巡查记录"
					@click="onPatrolLog"
				></up-button>
			</view>
		</view>
		
		<up-modal
			:show="showCallModal"
			closeOnClickOverlay
			@confirm="onCloseCall"
		>
			<view class="">
				<view class="pages-item-row">
					<text class="pages-hint-title" style="width: 300rpx;">曾文勇/应急办</text>
					<view class="pages-hint-content pages-hint-content--active" @click="onCallPerson">
						<up-icon
							name="phone" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="188****9090"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
				<view class="pages-item-row">
					<text class="pages-hint-title" style="width: 300rpx;">曾文勇/街道办</text>
					<view class="pages-hint-content pages-hint-content--active" @click="onCallPerson">
						<up-icon
							name="phone" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="188****9090"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
			</view>
		</up-modal>
	</view>
</template>

<script setup>
import { onLoad, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { onHasUserinfoData, onSetUserinfoData, onGetUserinfoData, onGetRoleIdData,  onSetRoleIdData, onSetRolesData, onGetRolesData } from "/common/userinfo.js"
import { onGetTask, onGetTaskDetails } from "/serves/api.js";


const tabs = ref([
	{ name: '基本信息', value: 'base' },
	{ name: '巡查记录（999）', value: 'log-1' },
	{ name: '整改记录', value: 'log-2' },
])
const active = ref('base')

// 切换tabs
const onSkipTabs = function (e) {
	active.value = e.value
}


const loadmore = ref('loadmore')
const count = ref(0)
const list = ref([])
const params = ref({
	pageNum: 1,
	pageSize: 10,
	
	taskName: null,
	taskType: null,
	startDate: null,
	endDate: null,
	
	belongTo: 100,
})

const showCallModal = ref(false)

const details = ref({})

const loading = ref(false)
const onPageGetTaskDetails = async (options) => {
	// const { id } = options
	const id = 1 
	loading.value = true
	
	try{
		const response = await onGetTaskDetails(id)
		const { data } = response
		const { task } = data
		details.value = task
	} finally {
		loading.value = false
	}
}

const onOpenMap = function () {
	uni.openLocation({
		latitude: 22.543610,
		longitude: 114.058032,
		success: function () {
			console.log('success');
		}
	});
}

const onCallPerson = function ()  {
	uni.makePhoneCall({
		phoneNumber: '18664306776',
		success: () => onCloseCall(),
		fail: () => {}
	})
}

const onOpenCall  = function (e)  {
	e.stopPropagation()
	showCallModal.value = true
}

const onCloseCall = function ()  {
	showCallModal.value = false
}
 

// 跳转至详情页面
const onSkipRouterToDetail = (item) => {
	console.log('me not K')
	// const { id } = item;
	const url = `/pages/site/details`
	uni.redirectTo({ url })
}

const onPatrolLog = ()=>{
	uni.navigateTo({
    url: '/pages/site/add'
  })
}

const onGetTaskList = async (refresh = false) => {
	loading.value = true
	loadmore.value = 'loading'
	try{
		const response = await onGetTask(params)
		const { rows, total } = response
		const temp = list.value
		rows.map(v => temp.push(v))
		count.value = total
		
		if (rows.length !== params.value.pageSize) loadmore.value = 'nomore'
		else loadmore.value = 'loadmore'
		
		if (refresh) {
			list.value = rows
			return
		}
		
		list.value = temp
	} finally {
		if (params.value.pageNum === 1) setTimeout(() => loading.value = false, 1800)
		else loading.value = false
	}
}


const scrolltolower  = function(e) {}

const onSelectOrg = function () {
	selectOrgRef.value.onShowPopup()
}

const onGoBack = function () {
	uni.navigateBack()
}

onLoad(() => onPageGetTaskDetails())
</script>

<style scoped lang="scss">
.pages {
	background-color: #fff;
}

.pages-map {
	width: 100%;
	height: 300rpx;
	box-sizing: border-box;
}

.pages-map-content {
	width: 100%;
	height: 100%;
}

.pages-content {
	box-sizing: border-box;
	width: 100%;
	height: calc(100vh - 388rpx);
	padding: 30rpx;
	padding-bottom: env(safe-area-inset-bottom);
	overflow: hidden;
	overflow-y: auto;
}

.pages-list-item {
	width: 100%;
	height: auto;
	background: #fff;
	transform: all 0.2s;
}

.pages-list-items {
	width: 100%;
	height: auto;
	background: linear-gradient(0deg, #FAFCFF 2%, #F6F9FF 100%);
	box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.1);
	border-radius: 4rpx;
	box-sizing: border-box;
	padding: 24rpx 30rpx;
	margin-bottom: 30rpx;
	position: relative;
	overflow: hidden;
	transform: all 0.2s;
	
	&:active {
		background: linear-gradient(0deg, #FAFCFF 2%, rgba(126, 187, 255, .2) 100%);
		box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.3);
	}
}

.pages-item-status {
	width: 150rpx;
	height: 150rpx;
	background-color: #317FFC;
	text-align: center;
	font-size: 24rpx;
	color: #FFFFFF;
	box-sizing: border-box;
	padding-top: 110rpx;
	transform: rotate(45deg);
	position: absolute;
	top: -75rpx;
	right: -75rpx;
	box-shadow: 4rpx 4rpx 4rpx 0px rgba(49, 127, 252, .3);
	
	&--warning {
		background-color: #FF9900;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(255, 153, 0, .3);
	}
	
	&--success {
		background-color: #00C500;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(0, 197, 0, .3);
	}
}

.pages-item-title {
	font-family: PingFangSC, PingFang SC;
	font-weight: 500;
	font-size: 36rpx;
	color: #171717;
	line-height: 1.5em;
	font-style: normal;
	width: 100%; 
	
	&--tag {
		padding: 5rpx 10rpx;
		font-size: 28rpx;
		color: #FF0000;
		border: 1px solid #FF0000;
		background-color: rgba(255, 0, 0, .1);
		margin-left: 20rpx;
		border-radius: 4rpx;
	}
}

.pages-item-row {
	width: 100%;
	min-height: 60rpx;
	height: auto;
	box-sizing: border-box;
	padding-top: 10rpx;
	display: flex;
	align-items: flex-start;
}

.pages-hint-title {
	width: 160rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-hint-content {
	display: inline-block;
	width: calc(100% - 160rpx);
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	transition: all .3s;
	
	&--active {
		padding-top: 5rpx;
		
		&:active {
			opacity: 0.9;
		}
	}
}

.pages-hint-content--flex {
	display: inline-flex;
	align-items: center;
}

.pages-hint-content--hint {
	margin-left: 10rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-item-bolck {
	width: 100%;
	height: auto;
}

.pages-bolck-title {
	height: 70rpx;
	display: flex;
	align-items: center;
	font-weight: 500;
	font-size: 30rpx;
	color: #000000;
	box-sizing: border-box;
}

.pages-bolck-title-ad {
	width: 6rpx;
	height: 32rpx;
	background-color: #317FFC;
	border-radius: 3rpx;
	margin-right: 15rpx;
}

.pages-bolck-content {
	width: 100%;
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	text-indent: 2em;
	line-height: 1.5em;
}

.pages-buttons--fill {
	width: 100%;
	height: calc(110rpx + env(safe-area-inset-bottom));
}

.pages-button {
	width: 100%;
	height: calc(110rpx + env(safe-area-inset-bottom));
	box-sizing: border-box;
	padding: 30rpx;
	box-shadow: 0px 2px 8px 0px rgba(0,0,0,0.18);
	position: fixed;
	bottom: 0;
	left: 0;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background-color: #ffffff;
}

</style>